import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class mix1 {
    private String sname;
    private String builtnum;
    private String dormnum;
    private String reason;

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public String getDormnum() {
        return dormnum;
    }

    public void setDormnum(String dormnum) {
        this.dormnum = dormnum;
    }

    public String getBuiltnum() {
        return builtnum;
    }

    public void setBuiltnum(String builtnum) {
        this.builtnum = builtnum;
    }

    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    @Override
    public String toString() {
        return "mix1{" +
                "sname='" + sname + '\'' +
                ", builtnum='" + builtnum + '\'' +
                ", dormnum='" + dormnum + '\'' +
                ", reason='" + reason + '\'' +
                '}';
    }

    //展现表中所有信息
    public static List<mix1> GetInforMix() throws Exception{
        String driverName = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/ckr";
        String username = "root";
        String password = "1234";
        PreparedStatement pstmt;
        ResultSet rs;
        Connection conn = JDBC1.getConnection(driverName, url, username, password);
        String sql="select * from upmix";
        pstmt = conn.prepareStatement(sql);
        rs = pstmt.executeQuery();
        List<mix1> list = new ArrayList<mix1>();
        while(rs.next()){
            mix1 mx = new mix1();
            mx.sname = rs.getString("Sname");
            mx.builtnum = rs.getString("BuiltNum1");
            mx.dormnum = rs.getString("DormNum1");
            mx.reason = rs.getString("Reason");
            list.add(mx);
        }
        return list;
    }
    //删除表中的一行信息
    public static void deleteMix(String reason1) throws Exception{
        String driverName = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/ckr";
        String username = "root";
        String password = "1234";
        PreparedStatement pstmt;
        ResultSet rs;
        Connection conn = JDBC1.getConnection(driverName, url, username, password);
        String sql="delete from upmix where Reason=?";
        pstmt = conn.prepareStatement(sql);
        pstmt.setString(1,reason1);
        pstmt.executeUpdate();
        pstmt.close();
        conn.close();
    }
}
